package com.enjoyor.health.HGPT.web.rest;

import com.alibaba.fastjson2.JSONObject;
import com.enjoyor.health.HGPT.service.BizNewsService;
import com.enjoyor.health.HGPT.web.CodeEnum;
import com.enjoyor.health.HGPT.web.RetResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Zhu Min
 * @date 2023/10/20 16:22
 */
@Api(value = "新闻", tags = {"新闻"})
@RestController
public class NewsController {

    @Autowired
    private BizNewsService bizNewsService;

    /**
     * 医学咨询
     */
    @RequestMapping(value = "/aiHealthReport/newsList", method = { RequestMethod.GET, RequestMethod.POST })
    public RetResult getMedicineNews(){
        return new RetResult().of(CodeEnum.SUCCESS).setResult(bizNewsService.getDBMedicineNews());
    }

    /**
     * 隐私协议
     */
    @RequestMapping(value = "/aiHealthReport/policy", method = { RequestMethod.GET, RequestMethod.POST })
    public RetResult getPrivacyPolicy(String policyId){
        return new RetResult().of(CodeEnum.SUCCESS).setResult(bizNewsService.getPolicyById(policyId));
    }

    /**
     * 意见反馈
     */
    @RequestMapping(value = "/aiHealthReport/feedback", method = { RequestMethod.GET, RequestMethod.POST })
    public RetResult getFeedback(String openId, String title, String content){
        if (bizNewsService.insertDbFeedback(title, content, openId)){
            return new RetResult().of(CodeEnum.SUCCESS);
        }else {
            return new RetResult().of(CodeEnum.SERVER_EXCEPTION);
        }
    }

    /**
     * 资讯
     */
    @RequestMapping(value = "/aiHealthReport/news", method = { RequestMethod.GET, RequestMethod.POST })
    public RetResult getNews(String newsId){
        JSONObject result = bizNewsService.getNewsById(newsId);
        return new RetResult().of(CodeEnum.SUCCESS).setResult(result);
    }

    /**
     * 资讯点赞
     */
    @RequestMapping(value = "/aiHealthReport/newsLikes", method = { RequestMethod.GET, RequestMethod.POST })
    public RetResult newsLikes(String newsId){
        bizNewsService.updateNewsLike(newsId);
        return new RetResult().of(CodeEnum.SUCCESS);
    }

}
